home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
- Subject: Re: C coding problem
- Date: 4 Apr 1996 18:50:24 -0600
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4k1qog$5mg@solutions.solon.com>
- References: <4ianbf$h86@solutions.solon.com> <4j41ru$nq4@solutions.solon.com> <4jttlq$3p1@solutions.solon.com> <4jv7dk$d1k@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4jv7dk$d1k@solutions.solon.com>,
- Konrad Schwarz <schwarz@mips.complang.tuwien.ac.at> wrote:
-
- >|> >for ( ; p<end_p; p++)
- >|> > ++(*p);
- >|>
- >|> or either of:
- >|>
- >|> while (p < end_p)
- >|> {
- >|> (*p)++;
- >|> p++;
- >|> }
- >|>
- >|> while (p++ < end_p)
- >|> {
- >|> (*p)++;
- >|> }
- >|>
- >|> Zero chance for ambiguity in the last three versions.
- >
- >The third version is not equivalent to the other two.
-
- By golly, you are right!
-
- It looks that our critic of obfuscated coding thinks that the side effect of
- p++ in the while() statement is not settled until the whole body of while()
- (including the compound statement) is executed---a common newbie assumption. I
- can see why he would want people to write code like:
-
- while (p < end_p)
- {
- *p = *p + 1;
- p = p + 1;
- }
-
- instead of
-
- while (p < end_p)
- ++*p++;
-
- --
-